import {Resource} from '../model/Resource'
import {MultipartFile} from '../model/MultipartFile'
import {ResponseEntity} from '../model/ResponseEntity'
import {String} from '../model/String'
import {RestResult} from '../model/RestResult'
import {void} from '../model/void'
import { Injectable } from '@angular/core';
import { AuthHttp } from 'angular2-jwt'
import { Observable } from "rxjs/Observable";
import { Environment } from '../environments/environment'
import 'rxjs/add/operator/map';
import { RestResult } from '../common/model/rest-result'

@Injectable()
export class  FileUploadControllerService {
  constructor (
    private http: AuthHttp,
    private env: Environment
  ){ }
  uploadFile(file: MultipartFile,id: number): Observable<string> {
    return this.http.post(this.env.urlPrefix + `/windbell/upload/${id}`+ `?file=${file}` ).map((res)=>{
    	let restResult = res.json() as RestResult<string>
    	return restResult.value
    })
  }
  uploadFile(file: MultipartFile): Observable<any /*TODO add explicit return type*/> {
    return this.http.post(this.env.urlPrefix + "/api/upload"+ `?file=${file}` ).map((res)=>{
    	let restResult = res.json() as RestResult<any /*TODO add explicit return type*/>
    	return restResult.value
    })
  }
  getDocument(id: number): Observable<void/*TODO: use RestResult as return type */> {
    return this.http.get(this.env.urlPrefix + `/documents/${id}` ).map((res)=>{
    	let restResult = res.json() as RestResult<void/*TODO: use RestResult as return type */>
    	return restResult.value
    })
  }
}
